
card_list = [];



func_list = ["新建名片","显示全部","查询名片","退出系统"];



def weilcom():
    print("");
    print("\n");
    print("*" * 40);
    print("欢迎使用【名片管理系统】V1.0")
    for item in func_list:

        if func_list.index(item) == 3:
            print("");
            print("{}.".format(0) + item);
        else:
            print("{}.".format(func_list.index(item) + 1) + item);
    print("*" * 40);

#新增名片
def cards_insert():
    print("_" * 50);
    name_str = input("请输入用户名:");
    age_str = input("请输入年龄:");
    email_str = input("请输入QQ邮箱:");
    salary_str = input("请输入工资:");

    card_info = {"name":name_str,
                 "age":age_str,
                 "email":email_str,
                 "salary":salary_str};
    card_list.append(card_info);
    print("名片添加成功")


def cads_all_show():
    print("_" * 50);
    print("功能: 显示全部")
    #判断是否存在名片记录，如果没有提示用户并且返回
    if len(card_list) <= 0:
        print("当前没有任何的名片记录请使用添加功能添加名片哦");
        return;
    #打印表头
    #print("姓名\t\t年龄\t\tQQ\t\t工资")
    for info in ("姓名","年龄","QQ","工资"):
        print(info,end="\t\t");
    print("")
    # 打印分割线
    print("_" * 50);
    for card_dict in card_list:
        print("%s\t\t%s\t\t%s\t\t%s" %(card_dict["name"],card_dict["age"],card_dict["email"],card_dict["salary"]));
    else:
        print("名片查询完毕")

def cads_search():
    print("_" * 50);
    print("搜索名片");
    #提示用户要搜索的姓名
    finde_name =  input("请输入要查询的名片名字:")
    #遍历列表
    for user_info in card_list:
        if finde_name.strip() == user_info["name"]:
            for info in ("姓名", "年龄", "QQ", "工资"):
                print(info, end="\t\t");
            print("");
            print("%s\t\t%s\t\t%s\t\t%s" % (user_info["name"], user_info["age"], user_info["email"], user_info["salary"]));


            deal_card(user_info);
            break;
    else:
        #没有找到提示用户
        print("该用户没有找到，请重新的输入名字");

#这里注意下哈，参数不用指定类型
def deal_card(card):
    """
     处理查找到的字符串
    :param card:
    :return:
    """
    while True:
        action_tag = input("请输入对名片的操作:"
                           "[1] 修改/ [2]: 删除/ [0]:返回上级菜单");
        if action_tag in ("1","2","0"):
            if(action_tag == "1"):
                # 开始修改card
                age_new = input_card_info(card["age"],"请输入年龄[回车不修改]:");
                email_new = input_card_info(card["email"],"请输入QQ邮箱[回车不修改]:");
                salary_str = input_card_info(card["salary"],"请输入工资[回车不修改]:");
                card["age"] = age_new;
                card["email"] = email_new;
                card["salary"] = salary_str;
                print("%s的名片修改成" %card["name"]);
            elif action_tag == "2":
                print("%s 的名片删除成功" % card["name"]);
                card_list.remove(card);
            return;
        else:
            print("选择有误请重新选择操作!");

#获取用户的card信息
def input_card_info(old_value,message_tip):
    """
    :param old_value:  字典中原有的值
    :param message_tip:  终端提示信息
    :return: 返回值
    """
    res = input(message_tip);
    if len(res) == 0:
        return old_value;
    else:

        return res;


